package hjt.com.module.main.fragment;


import android.content.Intent;
import android.os.Bundle;
import androidx.fragment.app.Fragment;
import androidx.recyclerview.widget.DividerItemDecoration;
import androidx.recyclerview.widget.LinearLayoutManager;
import androidx.recyclerview.widget.RecyclerView;
import android.view.View;

import com.alibaba.android.arouter.launcher.ARouter;
import com.tong.lib.adapter.recyclerview.MultiItemTypeAdapter;
import com.tong.lib.base.BaseFragment;

import java.util.ArrayList;
import java.util.List;

import butterknife.BindView;
import hjt.com.componentbase.constant.ARouterConstants;
import hjt.com.componentbase.service.ServiceFactory;
import hjt.com.module.main.R;
import hjt.com.module.main.R2;
import hjt.com.module.main.activity.WebviewActivity;
import hjt.com.module.main.adpter.MainAdpter;

/**
 * A simple {@link Fragment} subclass.
 */
public class FirstFragment extends BaseFragment {


    @BindView(R2.id.rlv)
    RecyclerView rlv;
    private List<String> dateList = new ArrayList<>();
    private MainAdpter mainAdpter;

    public FirstFragment() {
        // Required empty public constructor
    }

    @Override
    protected int getLayoutResID() {
        return R.layout.fragment_first;
    }

    @Override
    protected void init(Bundle savedInstanceState) {
        dateList.add("module_design_pattern");
        dateList.add("module_user");
        dateList.add("module_test");
        dateList.add("module_video");
        dateList.add("getToken");
        dateList.add("WebviewActivity");
        dateList.add("DragActivity");
        dateList.add("DragListActivity");
        rlv.setLayoutManager(new LinearLayoutManager(getActivity()));
        mainAdpter = new MainAdpter(getActivity(), dateList);
        rlv.addItemDecoration(new DividerItemDecoration(getActivity(), DividerItemDecoration.VERTICAL));
        rlv.setAdapter(mainAdpter);
    }

    @Override
    protected void initEvent() {
        mainAdpter.setOnItemClickListener(new MultiItemTypeAdapter.OnItemClickListener() {
            @Override
            public void onItemClick(View view, RecyclerView.ViewHolder holder, int position) {
                switch (position) {
                    case 0:
                        ARouter.getInstance()
                                .build(ARouterConstants.ACTIVITY_DESIGN_MAIN)
                                .navigation();
                        break;
                    case 1:
                        ARouter.getInstance()
                                .build(ARouterConstants.ACTIVITY_USER_SECOND)
                                .navigation();
                        break;
                    case 2:
                        ARouter.getInstance()
                                .build(ARouterConstants.ACTIVITY_TEST_TEST)
                                .navigation();
                        break;
                    case 3:
                        ARouter.getInstance()
                                .build(ARouterConstants.VIDEO_ACTIVITY_VIDEO)
                                .navigation();
                        break;
                    case 4:
                        show(ServiceFactory.getInstance().getLoginService().getToken());
                        break;
                    case 5:
                        startActivity(new Intent(getContext(), WebviewActivity.class));
                        break;
                    case 6:
                        ARouter.getInstance()
                                .build(ARouterConstants.ACTIVITY_TEST_DRAG)
                                .navigation();
                        break;
                    case 7:
                        ARouter.getInstance()
                                .build(ARouterConstants.ACTIVITY_TEST_DRAGLIST)
                                .navigation();
                        break;
                }
            }

            @Override
            public boolean onItemLongClick(View view, RecyclerView.ViewHolder holder, int position) {
                return false;
            }
        });
    }
}
